<?php
// +----------------------------------------------------------------------
// | @filename AuthController.php
// +----------------------------------------------------------------------
// | @author 落花轻舞问君愁 <mwcx1990@qq.com>
// +----------------------------------------------------------------------
// | @datetime 2021-10-27 09:41:18
// +----------------------------------------------------------------------
// | @Description
// +----------------------------------------------------------------------

namespace Addons\Backend\Http\Controllers;

use Addons\Backend\Http\Requests\Auth\LoginRequest;
use Addons\Backend\Logics\AuthLogic;


class AuthController extends BaseController
{
    protected $authLogic;

    public function __construct(AuthLogic $authLogic)
    {
        $this->authLogic = $authLogic;
        $this->middleware('auth:backend', ['except' => ['login']]);
    }

    /**
     * 登录
     * @param LoginRequest $request
     * @return mixed
     */
    public function login(LoginRequest $request)
    {
        $validated = $request->validated();
        $res = $this->authLogic->login($validated['username'], $validated['password']);
        return $this->respond($res);
    }

    /**
     * 退出登录
     * @return mixed
     */
    public function logout()
    {
        $res = $this->authLogic->logout();
        return $this->respond($res);
    }

    /**
     * 刷新登录token（token未过期前刷新）
     */
    public function refresh()
    {
        $res = $this->authLogic->refresh();
        return $this->respond($res);
    }
}
